﻿using System;
using Microsoft.Practices.Unity;

using SharedGenomics.Core.Configuration;
using SharedGenomics.DataAccess;
using SharedGenomics.Workbench.Presenters;
using SharedGenomics.Workbench.PresentationModel;
using SharedGenomics.Workbench.Models;

namespace SharedGenomics.Workbench.Core.Configuration
{
    public class PresenterContainerConfigurationStrategy : IContainerConfigurationStrategy
    {
        public void Configure(ContainerConfigurationContext context)
        {
            var container = context.Container;

            container.RegisterType<ILoginPresenter, LoginPresenter>();
            container.RegisterType<ILoginPrompt, LoginPrompt>();

            container.RegisterType<IEditUserMarkerPresenter, EditUserMarkerPresenter>();
            container.RegisterType<IFileBrowserPresenter, FileBrowserPresenter>();
            container.RegisterType<IOpenGenotypeFilePresenter, OpenGenotypeFilePresenter>();
            container.RegisterType<IOpenPhenotypeFilePresenter, OpenPhenotypeFilePresenter>();
            container.RegisterType<FileSetUploadPresenter>();
            container.RegisterType<DataFilterPresenter>();
            container.RegisterType<AnalysisResultsPresenter>();
            container.RegisterType<IAnalysisResultsModel, AnalysisResultsModel>();
            container.RegisterType<AnnotationResultsPresenter>();
            
            container.RegisterType<UcscBrowserPresenter>();
            container.RegisterType<IKeggPathwayFrequenciesModel, KeggPathwayFrequenciesModel>();
            container.RegisterType<KeggPathwayFrequenciesPresenter>();
            container.RegisterType<JobSubmissionPresenter>();
            container.RegisterType<IJobOptionsPresenterFactory, JobOptionsPresenterFactory>();
            container.RegisterType<AddSchemaPresenter>();
            container.RegisterType<ValidationErrorListPresenter>();
            container.RegisterType<IMainFormPresenter, MainFormPresenter>();
            container.RegisterType<CategoryFilterSetPresenter>();
            container.RegisterType<DataFilterResultsPresenter>();
            container.RegisterType<IDataFilterResultsModel, DataFilterResultsModel>();
            container.RegisterType<WatchListPresenter>();
            container.RegisterType<WatchListModel>();
            container.RegisterType<AnalysisResultsFilterPresenter>();
            container.RegisterType<IAvailableJobsModel, AvailableJobsModel>();

            var schemaFactory = new DataColumnSchemaFactory();
            schemaFactory.SetColumnTypeDefaultFormat<double>("F7");
            container.RegisterInstance<IDataColumnSchemaFactory>(schemaFactory);
            container.RegisterType<CategoryFilterPresenterFactory>();

            //analysis result model dependencies
            container.RegisterType<IAnalysisResultsRepository, AnalysisResultsRepository>();

            container.RegisterType<SharedGenomics.Domain.IAnalysisResultsFileReadStrategy, LineCountOrEmp1ThresholdAnalysisResultsFileReadStrategy>();

            //annotation presenters
            container.RegisterType<GeneSummaryPresenter>();
            container.RegisterType<NcbiSummaryPresenter>();
            container.RegisterType<TextMinedPublicationsPresenter>();
            container.RegisterType<WebBrowserPresenter>();

            container.RegisterType<IMissingMarkersModel, MissingMarkersModel>();

            //file parsers
            container.RegisterType<IMarkerWatchListParser, MarkerWatchListFileParser>();

            //register annotation viewers
            var menuProviders = new AnnotationMenuProviderRegistry();
            menuProviders.RegisterProvider(container.Resolve<WebSearchableAnnotationMenuProvider>());
            menuProviders.RegisterProvider(container.Resolve<TextMinedPublicationsAnnotationMenuProvider>());
            menuProviders.RegisterProvider(container.Resolve<KeggPathwayAnnotationMenuProvider>());
            menuProviders.RegisterProvider(container.Resolve<GeneSummaryAnnotationMenuProvider>());
            menuProviders.RegisterProvider(container.Resolve<NcbiSummaryAnnotationMenuProvider>());
            container.RegisterInstance<AnnotationMenuProviderRegistry>(menuProviders, new ContainerControlledLifetimeManager());
        }
    }
}
